import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {BaseService} from '../../../shared/service/base.service';
import {ApiUrl} from '../../../config/api-url';
import {Consts} from '../../../config/consts';

@Component({
  selector: 'app-commodity-info',
  templateUrl: './app-commodity-info.component.html',
  styleUrls: ['./app-commodity-info.component.less']
})
export class AppCommodityInfoComponent implements OnInit {
  // 模态框显隐
  @Input()
  isVisibleCommodityInfo = false;

  @Input()
  store: any;

  customerServiceInfo = [];
  userInfo: any;
  @Output()
  emit: EventEmitter<any> = new EventEmitter();
  serverFileUrl: any = Consts.imgUrl;
  constructor(private fb: FormBuilder, public baseService: BaseService) {
  }
  ngOnInit(): void {
    this.userInfo = JSON.parse(sessionStorage.getItem(Consts.USER_INFO));
  }
  ngOnChanges():void{
    if(this.isVisibleCommodityInfo && this.store != null){
      this.findMeiTuanPackageByStoreIdAndUserId();
    }
  }

  findMeiTuanPackageByStoreIdAndUserId(): void {
    let body = {
      id: this.store.id,
      outTradeNo: this.store.outTradeNo
    }
    console.log(body)
    this.baseService.post(ApiUrl.OrderItemUrl + '/findListByOrderId', body).subscribe(data => {
        if (data.status == 0) {
          this.customerServiceInfo = data.data;
          console.log(this.customerServiceInfo)
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }
  handleOk(){
    this.isVisibleCommodityInfo = false;
    this.emit.emit(this.isVisibleCommodityInfo);
    this.customerServiceInfo = [];
  }
}
